package kd.hc.dev.tpl;

import kd.bos.entity.datamodel.events.*;
import kd.bos.form.control.events.BeforeItemClickEvent;
import kd.bos.form.control.events.ItemClickEvent;
import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.sdk.plugin.Plugin;

import java.util.EventObject;
import java.util.HashMap;

/**
 * 批量值更新
 */
public class BatchValueUpdateFormPlugin extends AbstractFormPlugin implements Plugin {

    @Override
    public void beforeItemClick(BeforeItemClickEvent evt) {
        super.beforeItemClick(evt);
    }

    @Override
    public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
        super.afterDoOperation(afterDoOperationEventArgs);
        String operateKey = afterDoOperationEventArgs.getOperateKey();
        if ("doOk".equalsIgnoreCase(operateKey)) {
            Object textValue = this.getModel().getValue("hc95_text");
            HashMap<String, String> map = new HashMap<>();
            map.put("value", textValue == null ? "" : textValue.toString());
            this.getView().returnDataToParent(map);
            this.getView().close();
        }
    }

    @Override
    public void afterBindData(EventObject e) {
        super.afterBindData(e);
    }

    @Override
    public void itemClick(ItemClickEvent evt) {
        super.itemClick(evt);
    }

    @Override
    public void click(EventObject evt) {
        super.click(evt);
    }

}